<template>
  <view class="sort-container">
    <!-- 顶部导航栏 -->
    <view class="nav-bar">
      <view class="nav-left" @click="goBack">
        <uni-icons type="back" size="24"></uni-icons>
      </view>
      <view class="nav-title">排序</view>
    </view>
    
    <!-- 排序选项列表 -->
    <view class="sort-list">
      <view 
        class="sort-item" 
        v-for="(item, index) in sortOptions" 
        :key="index"
        :class="{ active: selectedSort === item.value }"
        @click="selectSort(item)"
      >
        <text>{{ item.label }}</text>
        <uni-icons v-if="selectedSort === item.value" type="checkmarkempty" size="20" color="#1890ff"></uni-icons>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      selectedSort: 'vacancy_desc',
      sortOptions: [
        { label: '空置天数从高到低', value: 'vacancy_desc' },
        { label: '空置天数从低到高', value: 'vacancy_asc' },
        { label: '价格从高到低', value: 'price_desc' },
        { label: '价格从低到高', value: 'price_asc' },
        { label: '面积从大到小', value: 'area_desc' },
        { label: '面积从小到大', value: 'area_asc' }
      ]
    }
  },
  methods: {
    goBack() {
      uni.navigateBack();
    },
    selectSort(item) {
      this.selectedSort = item.value;
      // 通知上一页更新排序方式
      uni.$emit('updateSort', item);
      uni.navigateBack();
    }
  }
}
</script>

<style lang="scss">
.sort-container {
  min-height: 100vh;
  background-color: #fff;
}

.nav-bar {
  display: flex;
  align-items: center;
  height: 90rpx;
  background-color: #fff;
  padding: 0 30rpx;
  position: relative;
  border-bottom: 1rpx solid #eee;
  
  .nav-left {
    position: absolute;
    left: 30rpx;
    height: 100%;
    display: flex;
    align-items: center;
  }
  
  .nav-title {
    flex: 1;
    text-align: center;
    font-size: 32rpx;
    font-weight: bold;
  }
}

.sort-list {
  padding: 0 30rpx;
  
  .sort-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100rpx;
    border-bottom: 1rpx solid #eee;
    
    text {
      font-size: 28rpx;
      color: #333;
    }
    
    &.active text {
      color: #1890ff;
    }
  }
}
</style>